import { Member } from "../model/member";
import { Sect } from "../model/sect";
import { Career } from "../model/career";
import { groupManager } from "./GroupManager";
import { messageMgr } from "./MessageMgr";
import utils from "../utils/util";
import { MemberUI } from "../ui/memberUI"
import { CareerType, SectType } from "../type/types";
import { userDataManager } from "./UserDataManager";
import { GroupUI } from "../ui/groupUI";
import { TeamMax, MemberMax } from "../init/init";
import { TeamUI } from "../ui/teamUI";
class UIGroupManager{
    private groupMap:Map<number, GroupUI>;
    private careerMap:Map<SectType, Sect>;
    private groupList:Array<GroupUI>;
    constructor(){
        this.groupMap = new Map<number,GroupUI>();
        this.careerMap = new Map<number,Sect>();
        this.groupList = new Array<GroupUI>();
    }
    public getGroupCount(){
        return this.groupList.length;
    }
    public addMember(groupId:number, teamIndex:number, memberUI:MemberUI){
        let group = groupManager.getGroup(groupId);
        if(group!=null){
            let team = group.getTeam(teamIndex);
            let memberId = utils.randMemberId(userDataManager.getUserId());
            let member = new Member(memberId, memberUI.name, memberUI.sect);
            team.add(member);
        }
    }
    public createGroup() : GroupUI|null{
        let groupUI = new GroupUI();
        for(let i=0;i<TeamMax;++i){
            groupUI.add(new TeamUI(MemberMax))
        }
       
        return groupUI;
    }

    public delMember(groupId:number, memberId:number){
        let group = groupManager.getGroup(groupId);
        if(group!=null && group.hasMember(memberId)){
            if(group.removeMember(memberId)){
                messageMgr.showTip(" member del successful");
            }
        }
    }
    init(){
        if(this.careerMap.size > 0) return;
        //1
        let zxg = new Career(CareerType.ZXG, "紫霞功");
        let txjy = new Career(CareerType.ZXG, "太虚剑意");
        let chunYang = new Sect(SectType.ChunYang, zxg, txjy);
        chunYang.setName("纯阳宫");
        this.careerMap.set(chunYang.getId(), chunYang);
        //2
        let hjy = new Career(CareerType.HJY, "花间游");
        let ljyd = new Career(CareerType.LJYD, "离经易道");
        let wanHua = new Sect(SectType.WanHua, hjy, ljyd);
        wanHua.setName("万花谷");
        this.careerMap.set(wanHua.getId(), wanHua);
        //3
        let yjj = new Career(CareerType.YJJ, "易筋经");
        let xsj = new Career(CareerType.XSJ, "洗髓经");
        let shaoLin = new Sect(SectType.ShaoLin, yjj, xsj);
        shaoLin.setName("少林寺");
        this.careerMap.set(shaoLin.getId(), shaoLin);
        //4
        let bxj = new Career(CareerType.BXJ, "冰心诀");
        let ycxj = new Career(CareerType.YCXJ, "云裳心经");
        let qiXiu = new Sect(SectType.QiXiu, bxj, ycxj);
        qiXiu.setName("七秀坊");
        this.careerMap.set(qiXiu.getId(), qiXiu);
        //5
        let axzy = new Career(CareerType.AXZY, "傲血战意");
        let tll = new Career(CareerType.TLL, "铁牢律");
        let tianCe = new Sect(SectType.TianCe, axzy, tll);
        tianCe.setName("天策府");
        this.careerMap.set(tianCe.getId(), tianCe);
        //6
        let wsj = new Career(CareerType.WSJ, "问水诀");
        let sjjy = new Career(CareerType.SJJY, "山居剑意");
        let cangJian = new Sect(SectType.CangJian, wsj, sjjy);
        cangJian.setName("藏剑山庄");
        this.careerMap.set(cangJian.getId(), cangJian);
        //7
        let dj = new Career(CareerType.DJ, "毒经");
        let btj = new Career(CareerType.BTJ, "补天诀");
        let wuDu = new Sect(SectType.WuDu, dj, btj);
        wuDu.setName("五毒教");
        this.careerMap.set(wuDu.getId(), wuDu);
        //8
        let jyj = new Career(CareerType.JYJ, "惊羽诀");
        let tlgd = new Career(CareerType.TLGD, "天罗诡道");
        let tangMen = new Sect(SectType.TangMen, jyj, tlgd);
        tangMen.setName("唐家堡");
        this.careerMap.set(tangMen.getId(), tangMen);
        //9
        let fysj = new Career(CareerType.FYSJ, "焚影圣诀");
        let mzllt = new Career(CareerType.MZLLT, "明尊琉璃体");
        let mingJiao = new Sect(SectType.MingJiao, fysj, mzllt);
        mingJiao.setName("明教");
        this.careerMap.set(mingJiao.getId(), mingJiao);
        //10
        let xcj = new Career(CareerType.XCJ, "笑尘诀");
        let gaiBang = new Sect(SectType.GaiBang, xcj);
        gaiBang.setName("丐帮");
        this.careerMap.set(gaiBang.getId(), gaiBang);
        //11
        let fsj = new Career(CareerType.FSJ, "分山劲");
        let tgy = new Career(CareerType.TGY, "铁骨衣");
        let cangYun = new Sect(SectType.CangYun, fsj, tgy);
        cangYun.setName("苍云军");
        this.careerMap.set(cangYun.getId(), cangYun);
        //12
        let mw = new Career(CareerType.MW, "莫问");
        let xz = new Career(CareerType.XZ, "相知");
        let changGe = new Sect(SectType.ChangGe, mw, xz);
        changGe.setName("长歌门");
        this.careerMap.set(changGe.getId(), changGe);
        //13
        let baj = new Career(CareerType.BAJ, "北傲诀");
        let baDao = new Sect(SectType.BaDao, baj);
        baDao.setName("霸刀山庄");
        this.careerMap.set(baDao.getId(), baDao);
        //14
        let lhj = new Career(CareerType.LHJ, "凌海诀");
        let pengLai = new Sect(SectType.PengLai, lhj);
        pengLai.setName("蓬莱");
        this.careerMap.set(pengLai.getId(), pengLai);
        //15
        let ylj = new Career(CareerType.YLJ, "隐龙诀");
        let lingXue = new Sect(SectType.LingXue, ylj);
        lingXue.setName("凌雪阁");
        this.careerMap.set(lingXue.getId(), lingXue);
        //16
        let txj = new Career(CareerType.TXJ, "太玄经");
        let yanTian = new Sect(SectType.YanTian, txj);
        yanTian.setName("衍天宗");
        this.careerMap.set(yanTian.getId(), yanTian);
        //17
        let wf = new Career(CareerType.WF, "无方");
        let ls = new Career(CareerType.LS, "灵素");
        let yaoZong = new Sect(SectType.YaoZong, wf, ls);
        yaoZong.setName("北天药宗");
        this.careerMap.set(yaoZong.getId(), yaoZong);
        //18
        let gfj = new Career(CareerType.GFJ, "孤风诀");
        let daoZong = new Sect(SectType.DaoZong, gfj);
        daoZong.setName("刀宗");
        this.careerMap.set(daoZong.getId(), daoZong);
        //19
        let shxj = new Career(CareerType.SHXJ, "山海心诀");
        let wanLing = new Sect(SectType.WanLing, shxj);
        wanLing.setName("万灵山庄");
        this.careerMap.set(wanLing.getId(), wanLing);
        //20
        let ztg = new Career(CareerType.ZTG, "周天功");
        let duanShi = new Sect(SectType.DuanShi, ztg);
        duanShi.setName("段氏");
        this.careerMap.set(duanShi.getId(), duanShi);
    }
    
}

export const groupUIManager = new UIGroupManager();